<?
  class Jeppii_Token_Int extends Jeppii_Token
  {
	private static $system_items = "ml680poiuyt5er3q1wsadgfhj4knvbcx2zPOITUYREWQASDFG9HJKLMNBVCXZ";
	private static $dataSeparator = "7";

    public static function encode($data)
	{ 
	  $system_items = self::$system_items;
	  $system_items_count = strlen($system_items);

	  while (1)
	  {
	  	$nr = (int)($data / $system_items_count);
	  	$roznica = $data - $nr * $system_items_count;

	  	if($nr == 0)
	  	{
	  	  $out .= $system_items[$roznica];
	  	  break;
	  	}
	  	else
	  	{
	  	  $out .= $system_items[$roznica];
	  	  $data = $nr;
	  	}
	  }
	  return $out;
	}

	public static function decode($trigger_string)
	{ 
	  $system_items = self::$system_items;
	  $system_items_count = strlen($system_items);

	  $nr = 0;
	  for($i = 0; $i < strlen($trigger_string); $i++)
	  {
	    $it = pow($system_items_count, $i);
	    $pos = strrpos($system_items, $trigger_string[$i]);
	    $nr += $pos*$it;//$system_items_count * $pos;
	  }
	  return $nr;
	}
	
	public static function encodeArray($data)
	{
	  $out .= "";
	  foreach ($data as $int)
	    $out .= self::encode($int).self::$dataSeparator;

	  return substr($out, 0, -1);
	}

	public static function decodeArray($trigger_string)
	{
	  $out = array();
	  foreach (explode(self::$dataSeparator, $trigger_string) as $str)
	  {
	    $out[] = self::decode($str);
	  }

	  return $out;
	}
	
  
  }
